layui.use([ 'form', 'layer', 'jquery'], function () {
    $ = layui.jquery;
    let form = layui.form,
        layer = layui.layer;

    findById();
    function findById() {
        let id = sessionStorage.getItem("navigationId");
        //console.log(id)
        $.ajax({
            url: '/back/navigation/id',
            data: {id: id},
            async:false,
            type: 'get',
            dataType: 'json',
            success: function (res) {
                if (res.data != null) {
                    setProductData(res.data);
                }
            }
        })
    }

    function setProductData(data) {
        //console.log(data);
        $("#name").val(data.name);
        $("#href").val(data.href);
        $(':radio[name="enable"][value="'+data.enable+'"]').prop("checked",true);
        $(':radio[name="isShow"][value="'+data.isShow+'"]').prop("checked",true);
    }

    //监听提交
    form.on('submit(edit)', function (data) {
            data = data.field;
            console.log(data);
            data.id = sessionStorage.getItem("navigationId")
            //console.log(data);
            //发异步，把数据提交给java
            $.ajax({
                url: '/back/navigation/update',
                data: data,
                type: 'post',
                dataType: 'json',
                success: function (res) {
                    if (res.count === 1) {
                        layer.alert("修改成功", {
                                icon: 6
                            },
                            function () {
                                //关闭当前frame
                                xadmin.close();

                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                    } else {
                        layer.alert("修改失败");
                    }

                }
            })
            return false;
        });
});